<template>
	<view>
		<view class="classMateList">
			<!-- 	<view class="item" v-for="(item,index) in key" :key="index">
				<view class="headImg">
					<van-image width="90rpx" height="90rpx" fit="cover" radius="10rpx"/>
				</view>
				<view class="nickName">

				</view>
			</view> -->
		</view>
		<van-notify id="van-notify" />
		<van-dialog id="van-dialog" confirm-button-color="#006600" @tap="getUserProfile(e)" />
	</view>
</template>

<script>
	import Dialog from '../../wxcomponents/vant/dist/dialog/dialog';
	import Notify from '../../wxcomponents/vant/dist/notify/notify';
	export default {
		data() {
			return {
				map: {},
				key: []
			}
		},
		onLoad() {
			this.getUserInfo()
			this.getMyNotes()
		},
		onshow() {

		},
		methods: {
			getMyNotes() {
				let self = this
				uni.request({
					url: getApp().globalData.baseURL + "/note/getNotes",
					data: {
						"openid": wx.getStorageSync('openid')
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						// var map = res.data
						// console.log(map)
						var str = res.data;
						console.log(res.data)
						var jsonStr = str.replace(" ", "");
						if (typeof jsonStr != 'object') {
							jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
							var jj = JSON.parse(jsonStr);
							res.data = jj;
						}
						console.log(jj)
						// console.log(map)
						// 	let _key = []
						// 	for (var key in map) {
						// 		// _key.push(key)
						// 	}
						// self.key = _key

					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			getUserInfo() {
				let self = this
				uni.request({
					url: getApp().globalData.baseURL + "/user/getUser",
					data: {
						"openid": wx.getStorageSync('openid')
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						if (res.data.code === 1) {
							if (res.data.data.headImg === null) {
								// 未完善个人信息,需要拿到学校,昵称
								Dialog.alert({
									message: '您还未完善个人信息,只有完善信息后才能使用小纸条哦',
									confirmButtonText: '去完善'
								})
							}
						} else {
							Dialog.alert({
								message: '您还未完善个人信息,只有完善信息后才能使用小纸条哦',
								confirmButtonText: '去完善'
							})
						}
					},
					fail: (err) => {
						Notify({
							type: 'danger',
							message: '获取个人信息失败,请检查您的网络连接'
						});
					}
				})
			},
			getUserProfile(e) {
				let self = this
				wx.getUserProfile({
					desc: "用于完善用户资料",
					success: (res) => {
						self.addAUserInfo(res)
					},
					fail: (err) => {
						uni.navigateBack()
					}
				})
			},
			addAUserInfo(res) {
				uni.request({
					url: getApp().globalData.baseURL + "/userInf/addAUserInf",
					data: {
						"openid": wx.getStorageSync('openid'),
						"nickname": res.userInfo.nickName,
						"headImg": res.userInfo.avatarUrl
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						// console.log(res)
					},
					fail: (err) => {
						Notify({
							type: 'danger',
							message: '添加用户信息失败'
						});
					}
				})
			},
		}
	}
</script>

<style scoped>
	.classMateList {}

	.classMateList .headImg {}
</style>
